package com.link.base.base.accnt.controller;

import com.link.base.base.accnt.model.RegisterAudit;
import com.link.base.base.accnt.service.RegisterAuditService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * DMS注册审核-DMS注册审核
 *
 * @author 黄正杨
 * @date 2019/03/19 18:39
 */
@Controller
@RequestMapping("/link/registerAudit")
public class RegisterAuditController extends BasicController<RegisterAudit> {


    @Resource
    private RegisterAuditService registerAuditService;


    @Override
    public BasicService<RegisterAudit> getBasicService() throws Exception {
        return registerAuditService;
    }

    /**
     *同意注册
     *
     * @author 黄正杨
     * @date 2019/03/20
     * @param audit
     * @return Map
     */
    @RequestMapping("/agreeRegister")
    @ResponseBody
    public Map<String, Object> agreeRegister(@JsonParam RegisterAudit audit) {
        Map<String, Object> map = new HashMap<>(4);
        try {
            registerAuditService.agreeRegister(audit);
            map.put("success", true);
        } catch (BasicServiceException e) {
            map.put("success", false);
            map.put("result", e.getMessage());
            map.put("detailMessage", e.getDetailMessage());
            map.put("code", e.getCode());
        } catch (Exception e) {
            map.put("success", false);
            map.put("result", e.getMessage());
            map.put("code", "400");
        }
        return map;
    }

    /**
     * 拒绝注册
     *
     * @author 黄正杨
     * @date 2019/03/20
     * @param audit
     * @return Map
     */
    @RequestMapping("/refuseRegister")
    @ResponseBody
    public Map<String, Object> refuseRegister(@JsonParam RegisterAudit audit) {
        Map<String, Object> map = new HashMap<>(4);
        try {
            registerAuditService.refuseRegister(audit);
            map.put("success", true);
        } catch (BasicServiceException e) {
            map.put("success", false);
            map.put("result", e.getMessage());
            map.put("detailMessage", e.getDetailMessage());
            map.put("code", e.getCode());
        } catch (Exception e) {
            map.put("success", false);
            map.put("result", e.getMessage());
            map.put("code", "400");
        }
        return map;
    }
}
